package gtgold;

import java.io.Serializable;

/**
 * Encapsulates ferry delay information
 * 
 * @author jo
 */
public class DelayManager implements Serializable
{
	private static final long serialVersionUID = 1L;
	public int restLength = 0;
	public int ferryWait = -1; // If positive number of days till ferry is ready. -1 means we haven't paid for verry
	
	public Item brokenPiece = null; //Is there a broken wheel, axle, etc.? Only one can be broken at a time

	public String weather = null;
	public int weatherLength = 0;
	
	public boolean repairingWagon = false;
	
	/**
	 * @return true if delayed, false else
	 */
	boolean delayed()
	{
		return repairingWagon || restLength > 0 || ferryWait > 0 || weatherLength > 0;
	}

	/**
	 * 
	 * @return Description of delays if any
	 */
	String reason(){
		if (repairingWagon) {return "Repairing wagon";}
		if (weatherLength > 0) {return "Delayed by " + weather.toLowerCase();}
		if (ferryWait > 0) {return "Waiting for ferry";}
		if (restLength > 0) {return "Resting";}
		return null;
	}
	
	/**
	 * Simulates a day's wait
	 */
	void update()
	{
		repairingWagon = false;
		
		if (restLength > 0)
		{
			--restLength;
		}

		if (ferryWait > 0)
		{
			--ferryWait;
		}
		
		if (weatherLength > 0)
		{
			--weatherLength;
			
			if (weatherLength == 0) {weather = null;}
		}
	}
}
